﻿// Study1009.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十章 STL和泛型设计 关联容器 集合set

#include <iostream>
#include <set>
#include <iterator>
using namespace std;

int main()
{
	set<double> s;
	cout << "输入实数(输入0退出)：" << endl;
	while (true)
	{
		double v;
		cin >> v;
		if (v==0)
		{
			break;
		}
		pair<set<double>::iterator, bool> r = s.insert(v);
		if (!r.second)
		{
			cout << v << "is duplicated!" << endl;
		}
		
	}
	set<double>::iterator iter1, iter2;
	iter1 = s.begin();
	iter2 = s.end();
	double medium = (*iter1 + *(--iter2)) / 2;
	cout << "medium=" << medium << endl;
	cout << "<=medium:";
	copy(s.begin(), s.upper_bound(medium), ostream_iterator<double>(cout, " "));
	cout << endl;
	cout << ">=medium:";
	copy(s.lower_bound(medium),s.end(), ostream_iterator<double>(cout, " "));
	cout << endl;
	return 0;
}


